const CollectionModel = require('../db/models/collection');

class CollectionService {
   async addCollection (data) {
       const cid = data.cid;

    const result = await CollectionModel.findOne({
        where: { cid }
    });
    if(result){
        return await CollectionModel.updata(data, {
            where: { cid }
        });
    }else {
        return await CollectionModel.create(data);
    }
   }

   async getCollectionData () {
       return await CollectionModel.findAll({
           attributes: {
               exclude: ['posterKey','courseIdList']
           }
       })
   }

   async changeCollectionStatus (id, status) {
       const res = await CollectionModel.update({ status }, {
           where: { id }
       })

       return res[0];
   }
}

module.exports = new CollectionService();